package com.tengju.data.infrastructure.repository.clickhouse.star;

import com.tengju.data.domain.model.clickhouse.star.StarChangeNoticeRecord;
import com.tengju.data.domain.model.clickhouse.star.StarChangeNoticeRecordRepository;
import com.tengju.data.domain.model.clickhouse.star.StarChangeNoticeType;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.StarChangeNoticeRecordDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.star.BigDataStarChangeNoticeRecordDOMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.StarConvert;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenhang
 * @Date 2021/3/26
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class StarChangeNoticeRecordRepositoryImpl implements StarChangeNoticeRecordRepository {

    private final BigDataStarChangeNoticeRecordDOMapper starChangeNoticeRecordDOMapper;


    @Override
    public List<StarChangeNoticeRecord> listStarChangeNoticeRecord(StarChangeNoticeType type, List<UserIdCode> idCodes) {
        if (CollectionUtils.isEmpty(idCodes)) {
            return Collections.emptyList();
        }
        List<Long> idCodeValues = idCodes.stream().map(UserIdCode::getValue).collect(Collectors.toList());
        List<StarChangeNoticeRecordDO> starChangeNoticeRecordDOList = starChangeNoticeRecordDOMapper
                .listStarChangeNoticeRecord(type.getType(),idCodeValues);
        if (CollectionUtils.isEmpty(starChangeNoticeRecordDOList)) {
            return Collections.emptyList();
        }
        return starChangeNoticeRecordDOList.stream()
                .map(StarConvert::toStarChangeNoticeRecordDO)
                .collect(Collectors.toList());
    }
}
